package d1202.Ljs2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Demo1 {
    public static void main(String[] args) {
        ArrayList<Dog>dogs=new ArrayList<>();
        dogs.add(new Dog("哈士奇",1,3));
        dogs.add(new Dog("藏獒",2,12));
        dogs.add(new Dog("博美",2,6));
        dogs.add(new Dog("柴犬",3,12));

        System.out.println("排序前："+dogs);

        Collections.sort(dogs, new Comparator<Dog>() {
            @Override
            public int compare(Dog o1, Dog o2) {
                if (o1.getAge()!=o2.getAge()){
                return -1;
            }else if (o1.getAge()==o2.getAge()){
                    return o2.getWeight()-o1.getWeight();
                }else {
                    return 1;
                }
            }
        });
        System.out.println("排序后："+dogs);
    }
}
